import http from '@/utils/http'
import { praseStrEmpty } from '@/utils/common'

// 查询用户列表
export function listUser (params) {
  return http({
    url: '/system/user/list',
    method: 'post',
    data: http.adornData(params)
  })
}

// 查询用户详细
export function getUser (userId) {
  return http({
    url: '/system/user/info/' + praseStrEmpty(userId),
    method: 'get'
  })
}

// 新增用户
export function addUser (data) {
  return http({
    url: '/system/user/save',
    method: 'post',
    data: http.adornData(data)
  })
}

// 修改用户
export function updateUser (data) {
  return http({
    url: '/system/user/update',
    method: 'post',
    data: http.adornData(data)
  })
}

// 删除用户
export function delUser (userId) {
  return http({
    url: '/system/user/delete/' + userId,
    method: 'post'
  })
}

// 导出用户
export function exportUser (params, filename) {
  return http.download('system/user/export', { ...params }, filename)
}

// 用户密码重置
export function changeUserPwd(data) {
  return http({
    url: '/system/user/password',
    method: 'post',
    data: http.adornData(data)
  })
}

// 用户状态修改
export function changeUserStatus (id, status) {
  const data = {
    id,
    status
  }
  return http({
    url: '/system/user/changeStatus',
    method: 'post',
    data: http.adornData(data)
  })
}

// 重置用户
export function resetUser(userId) {
  return http({
    url: '/system/user/reset/' + userId,
    method: 'post'
  })
}

// 用户状态修改
export function lockUser(userId) {
  return http({
    url: '/system/user/lock/' + userId,
    method: 'post'
  })
}

// 用户状态修改
export function unlockUser(userId) {
  return http({
    url: '/system/user/unlock/' + userId,
    method: 'post'
  })
}

// 查询用户个人信息
export function getUserProfile () {
  return http({
    url: '/system/profile/info',
    method: 'get'
  })
}

// 修改用户个人信息
export function updateUserProfile (data) {
  return http({
    url: '/system/profile/update',
    method: 'post',
    data: http.adornData(data)
  })
}

// 修改个人密码
export function changeProfilePwd(data) {
  return http({
    url: '/system/profile/password',
    method: 'post',
    data: http.adornData(data)
  })
}

// 用户头像上传
export function uploadAvatar (data) {
  return http({
    url: '/system/user/profile/avatar',
    method: 'post',
    data: http.adornData(data)
  })
}

// 下载用户导入模板
export function importTemplate(filename) {
  return http.download('system/user/importTemplate', {}, filename)
}

// 校验用户名称唯一性
export function checkUsernameUnique (data) {
  return http({
    url: '/system/user/checkUsernameUnique',
    method: 'get',
    params: http.adornParams(data)
  })
}
export function checkEmailUnique (data) {
  return http({
    url: '/system/user/checkEmailUnique',
    method: 'get',
    params: http.adornParams(data)
  })
}
export function checkPhoneUnique (data) {
  return http({
    url: '/system/user/checkPhoneUnique',
    method: 'get',
    params: http.adornParams(data)
  })
}
// 查询用户详细
export function listUserInfoByIds (userIds) {
  return http({
    url: `/system/user/listUserInfoByIds/${userIds}`,
    method: 'get'
  })
}
